package com.cskaoyan.lz_service;

import com.cskaoyan.bean.Collect;
import com.cskaoyan.bean.lzpackage.lz_collect.CollectData;
import com.cskaoyan.bean.params.BaseParam;
import com.cskaoyan.mapper.CollectMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CollectServiceImpl implements CollectService {

    @Autowired
    CollectMapper collectMapper;
    @Override
    public CollectData query(BaseParam param, String username,String userId,String valueId) {
        Integer page = param.getPage();//页码
        Integer limit = param.getLimit();//数据量
        String sort = param.getSort();//排序列
        String order = param.getOrder();//desc\asc
        //分页插件 PageHelper，辅助我们做分页以及分页信息的获得
        PageHelper.startPage(page, limit);
        //执行查询过程中拼接分页信息
        List<Collect> list = collectMapper.select(sort,order,username,userId,valueId);
        //total、pages、list
        //通过PageHelper帮我们来获得一些和分页相关的信息PageInfo
        //使用其有参构造方法 → 形参写来源于数据库的list
        PageInfo<Collect> pageInfo = new PageInfo<>(list);
        long total = pageInfo.getTotal();
        int pages = pageInfo.getPages();
        return CollectData.data(total,pages,limit,page,list);
    }
}
